
unset PATH
unset PACKAGE_CONF
unset PRODUCT_DIR

if [ $# -eq 1 ]
then
    PACKAGE_CONF=stuff.conf
    PRODUCT_DIRECTORY=${1}
elif [ $# -eq 2 ]
then
    PACKAGE_CONF=${1}
    PRODUCT_DIRECTORY=${2}
else
    PACKAGE_CONF=package.conf
    PRODUCT_DIRECTORY=helloworld    
fi

source ${PACKAGE_CONF}
source ${PRODUCT_DIRECTORY}/${PRODUCT_DIRECTORY}.conf

${RM} --recursive --force ${PRODUCTION_DIRECTORY} ${WORKING_DIRECTORY}
${MKDIR} --parents ${PRODUCTION_DIRECTORY}/SPECS
${SED} \
    -e "s/Name:      \${NAME}/Name:      ${NAME}/" \
    -e "s/Version:   \${VERSION}/Version:   ${VERSION}/" \
    -e "s/Release:   \${RELEASE}/Release:   ${RELEASE}/" \
    -e "s/Source:    \${NAME}-\${VERSION}.tar.gz/Source:    ${NAME}-${VERSION}.tar.gz/" \
    -e "s/BuildRoot: \/home\/Bfs34ruV\/rpmbuild\/\${NAME}-\${VERSION}-root/BuildRoot: \/home\/Bfs34ruV\/rpmbuild\/${NAME}-${VERSION}-root/" \
    ${PRODUCT_DIRECTORY}/${NAME}.spec > ${PRODUCTION_DIRECTORY}/SPECS/${NAME}-${VERSION}.spec
${MKDIR} --parents ${WORKING_DIRECTORY}/src/${NAME}-${VERSION}
${CD} ${PRODUCT_DIRECTORY}/src
${CP} --target-directory=${WORKING_DIRECTORY}/src/${NAME}-${VERSION} -p --parents ${SOURCES} 
${MKDIR} --parents ${WORKING_DIRECTORY}/tar
${TAR} --create --file=${WORKING_DIRECTORY}/tar/${NAME}-${VERSION}.tar --directory=${WORKING_DIRECTORY}/src ${NAME}-${VERSION}
${MKDIR} --parents ${PRODUCTION_DIRECTORY}/SOURCES
${GZIP} --to-stdout ${WORKING_DIRECTORY}/tar/${NAME}-${VERSION}.tar > ${PRODUCTION_DIRECTORY}/SOURCES/${NAME}-${VERSION}.tar.gz
${MKDIR} --parents ${PRODUCTION_DIRECTORY}/BUILD
${MKDIR} --parents ${PRODUCTION_DIRECTORY}/RPMS
${MKDIR} --parents ${PRODUCTION_DIRECTORY}/SRPMS
${RPMBUILD} -v -bb ${PRODUCTION_DIRECTORY}/SPECS/${NAME}-${VERSION}.spec
${CP} cp /home/Bfs34ruV/rpmbuild/RPMS/i386/*.rpm /tmp